package com.sky.mapper;

import com.github.pagehelper.Page;
import com.sky.annotation.AutoFill;
import com.sky.dto.DishDTO;
import com.sky.dto.DishPageQueryDTO;
import com.sky.entity.Category;
import com.sky.entity.Dish;
import com.sky.enumeration.OperationType;
import com.sky.vo.DishVO;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;
import java.util.Map;

/**
 * @Auther: zhaoss
 * @Date: 2023/4/29 - 04 - 29 - 17:59
 * @Description: com.sky.mapper
 * @version: 1.0
 */
@Mapper
public interface DishMapper {
    /**
     * 通过分类id查询
     */
    @Select("select count(id) from dish where category_id = #{categoryId}")
    Integer getByCategoryId(Long categoryId);


    /**
     * 根据名称查询
     * @param name
     * @return
     */
    @Select("select * from dish where name = #{name}")
    Dish getByName(String name);

    /**
     * 新增菜品
     * @param dish
     * @return
     */
//    @Insert("insert into dish (name, category_id, price, image, description,status, create_time, update_time, create_user, update_user) " +
//            "values (#{name},#{categoryId},#{price},#{image},#{description},#{status},#{createTime},#{updateTime},#{createUser},#{updateUser}) ")
    @AutoFill(OperationType.INSERT)
    void save(Dish dish);

    /**
     * 分页查询
     * @param dto
     * @return
     */
    Page<DishVO> page(DishPageQueryDTO dto);

    /**
     * 根据id集合删除菜品
     * @param dishIds
     * @return
     */
    public int deleteDish(List<Long> dishIds);
    /**
     * 根据主键查询菜品
     *
     * @param id
     * @return
     */
    @Select("select * from dish where id = #{id}")
    Dish getById(Long id);

    /**
     * 修改菜品表
     * @param dish
     */
    @AutoFill(OperationType.UPDATE)
    void updateDishById(Dish dish);


    //单一查询
    List<Dish> getByCategoryId2(Long id);

    /**
     * 根据条件统计菜品数量
     * @param map
     * @return
     */
    Integer countByMap(Map map);
}
